package com.invite.me.ui.yaoyue;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.invite.me.R;
import com.invite.me.base.BaseActivity;
import com.invite.me.beans.adpater.BlindDataParticularsAdpater;
import com.invite.me.beans.adpater.MyInfoAdpater;
import com.invite.me.beans.fabean.BlindDataPartiicularsFaBean;
import com.invite.me.beans.presenter.BlindDataParticularsPresenter;
import com.invite.me.beans.presenter.InviteRecordDetailPresenter;
import com.invite.me.beans.res.BlindDataParticularsBean;
import com.invite.me.ui.ditu.MapYaoYueActivity;
import com.invite.me.util.SspPrefUtils;
import com.invite.me.util.ToastUtils;
import com.invite.me.wlqq.Constants;
import com.invite.me.wlqq.Contract;
import com.library.flowlayout.FlowLayoutManager;
import com.library.flowlayout.SpaceItemDecoration;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class BlindDataParticularsActivity extends BaseActivity implements View.OnClickListener,Contract.BaseView{
    BlindDataParticularsPresenter blindDataParticularsPresenter;
    private ImageView touxiang;
    private ImageView tubiao;
    private TextView name;
    private TextView pricexs;
    private TextView quzhifu;
    private TextView yaoyuedizhitext;
    private RecyclerView recyclerviwemyzl;
    private RecyclerView tubiaodianji;
    private LinearLayout yaoyuedizhi;
    BlindDataParticularsAdpater blindDataParticularsAdpater;
    List<BlindDataPartiicularsFaBean.DataBean.MyTagListBean> myTagList = new ArrayList<>();
    private String xiangxidizhi;
    private String id;
    private double price;

    @Override
    protected void initView() {
        Intent intent = getIntent();
        id = intent.getStringExtra("id");


        blindDataParticularsPresenter=new BlindDataParticularsPresenter(this);
        blindDataParticularsPresenter.loadHomeData(id);
        //头像
       ImageView image_fanhui = findViewById(R.id.image_fanhui);
        touxiang = findViewById(R.id.touxiang);
        quzhifu = findViewById(R.id.quzhifu);
        name = findViewById(R.id.name);
        tubiao = findViewById(R.id.tubiao);
        yaoyuedizhitext = findViewById(R.id.yaoyuedizhitext);
        recyclerviwemyzl = findViewById(R.id.recyclerviwemyzl);
        FlowLayoutManager flowLayoutManager = new FlowLayoutManager();
        recyclerviwemyzl.addItemDecoration(new SpaceItemDecoration(dp2px(5)));
        recyclerviwemyzl.setLayoutManager(flowLayoutManager);
        blindDataParticularsAdpater=new BlindDataParticularsAdpater(R.layout.zuijintext_list,myTagList);
        recyclerviwemyzl.setAdapter(blindDataParticularsAdpater);


        //标题
        tubiaodianji = findViewById(R.id.tubiaodianji);
        yaoyuedizhi = findViewById(R.id.yaoyuedizhi);
        pricexs = findViewById(R.id.pricexs);
        image_fanhui.setOnClickListener(this);
        yaoyuedizhi.setOnClickListener(this);
        quzhifu.setOnClickListener(this);


    }
    private int dp2px(float value) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, getResources().getDisplayMetrics());
    }
    @Override
    protected int getActivityLayoutId() {
        return R.layout.activity_blindataparticulars;
    }

    @Override
    protected void loadData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.image_fanhui:
                finish();
                break;
            case R.id.quzhifu:
                //纬度
                String string = SspPrefUtils.getString(Constants.FAQIYAOYUEWEIDU, "");
                //精度
                String string1 = SspPrefUtils.getString(Constants.FAQIYAOYUEJINGDU, "");
                //城市
                String string2 = SspPrefUtils.getString(Constants.CHENGSHI, "");
                //区域
                String string3 = SspPrefUtils.getString(Constants.QUYU, "");
                //省
                String string4 = SspPrefUtils.getString(Constants.SHENG, "");
                if(TextUtils.isEmpty(xiangxidizhi)){
                    ToastUtils.show(BlindDataParticularsActivity.this,"请选择地址");
                   return;
                }else if(TextUtils.isEmpty(string)){
                    ToastUtils.show(BlindDataParticularsActivity.this,"请选择地址");
                    return;
                }else if(TextUtils.isEmpty(string1)){
                    ToastUtils.show(BlindDataParticularsActivity.this,"请选择地址");
                    return;
                }
                //自己id
                String string5 = SspPrefUtils.getString(Constants.SSPTOKEN, "");
                double v1 = Double.parseDouble(string);
                double v2 = Double.parseDouble(string1);
                blindDataParticularsPresenter.faqiyaoyue(xiangxidizhi,string2,string3,"1",v1,v2,string4,string5,id,price);



                break;
            case R.id.yaoyuedizhi:
                Intent ditu=new Intent(BlindDataParticularsActivity.this,MapYaoYueActivity.class);
                startActivity(ditu);


                break;

        }

    }

    @Override
    public void setPresenter(Contract.BasePresenter basePresenter) {
        if (blindDataParticularsPresenter instanceof Contract.BasePresenter) {
            this.blindDataParticularsPresenter = (BlindDataParticularsPresenter) basePresenter;
        }
    }

    @Override
    public void onDataSucess(Object o){
        if(o instanceof BlindDataPartiicularsFaBean){
            BlindDataPartiicularsFaBean blindDataPartiicularsFaBean= (BlindDataPartiicularsFaBean) o;
            if(blindDataPartiicularsFaBean.getCode()==1000){
                String discribe = blindDataPartiicularsFaBean.getData().getDiscribe();
                int sex = blindDataPartiicularsFaBean.getData().getSex();
                String nickname = blindDataPartiicularsFaBean.getData().getNickname();
                price = blindDataPartiicularsFaBean.getData().getPrice();
                pricexs.setText(price +"");
                Glide.with(this)
                        .load(discribe)
                        .apply(RequestOptions.bitmapTransform(new RoundedCorners(20)))//圆角半径
                        .into(touxiang);
                if(sex==1){
                    tubiao.setImageResource(R.mipmap.nanbiaoshi);
                }else if(sex==2){
                    tubiao.setImageResource(R.mipmap.nxbs);
                }
                name.setText(nickname);
                myTagList.addAll(blindDataPartiicularsFaBean.getData().getMyTagList());

                blindDataParticularsAdpater.notifyDataSetChanged();



            }



        }


    }

    @Override
    public void onDataFaile(Object o) {

    }

    @Override
    public void onComplete() {

    }

    @Override
    protected void onResume() {
        super.onResume();
        xiangxidizhi = SspPrefUtils.getString(Constants.QUEDINGDIZHI, "");
        if(!TextUtils.isEmpty(xiangxidizhi)){
            yaoyuedizhitext.setText(xiangxidizhi);
        }



    }
}
